package com.usian.controller;

import com.usian.pojo.CartItem;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class CartController {

    @RequestMapping("findCart")
    public String findCart(){
        return "购物车的数据一堆---3";
    }

    @RequestMapping("hello")
    public String hello(){
        return "hello";
    }

    @RequestMapping("addCartItem")   //http://xxx:xx/addCartItem?goodId=xx&num=xxx  表单类型的提交
    public String addCartItem(@RequestParam("goodsId") String goodsId,@RequestParam("num") Integer num){
        System.out.println("进行购物车的新增"+goodsId+":"+num);
        return "add success------------";
    }

    @RequestMapping("addCartItem2/{goodsId}")   //http://xxx:xx/addCartItem?xx/xx  rest风格
    public String addCartItem2(@PathVariable("goodsId") String goodsId, @PathVariable("num") Integer num){
        System.out.println("进行购物车的新增2"+goodsId+":"+num);
        return "add success2------------";
    }

    @RequestMapping("addCartItem3")   //http://xxx:xx/addCartItem?xx/xx    json对象 json字符串
    public String addCartItem3(@RequestBody CartItem cartItem){
        System.out.println("进行购物车的新增3"+cartItem.getGoodsId()+":"+cartItem.getNum());
        return "add success3------------";
    }

    @RequestMapping("addCartItem4")   //http://xxx:xx/addCartItem?xx/xx  Map
    public String addCartItem4(@RequestBody Map cartItem){
        System.out.println("进行购物车的新增4"+cartItem.get("goodsId")+":"+cartItem.get("num"));
        return "add success4------------";
    }

}
